package com.zou.szt;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.zou.szt.Utils.GetCards;

/**
 * Created by zou on 2016/5/20.
 */
public class RemoveDialogFragment extends BaseDialogFragment {

    OnSubmitListener listener;


    @Override
    public void onAttach(Activity activity) {
//        添加Fragment时调用，在其中初始化listener
        super.onAttach(activity);
        listener = (OnSubmitListener) activity;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        final String number = getArguments().getString("number");

        LayoutInflater mInflater = LayoutInflater.from(getActivity());
        View view = mInflater.inflate(R.layout.dialog_remove, null);


        TextView num = (TextView) view.findViewById(R.id.remove_num);
        Button yesbtn = (Button) view.findViewById(R.id.btn_yes);
        Button nobtn = (Button) view.findViewById(R.id.btn_no);


        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setView(view).setTitle("删除深圳通");

        num.setText("确认删除深圳通 " + number + "?");


        nobtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });


        yesbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GetCards.removeCards(getContext(), number);
                listener.sendMessage("whatever");
                dismiss();
            }
        });

        return builder.create();
    }
}
